<template>
	<view class="page">
		<!-- 搜索框 -->
		<view class="article-search">
			<view class="search">
				<view class="location" @click="getLocation">
					<view class="iconfont icon-dingwei"></view> <!-- 这里可以换成定位图标 -->
				</view>
				<input type="text" placeholder="输入搜索内容" v-model="searchQuery" @confirm="onSearch" />
				<view class="search-button" @click="onSearch">搜索</view>
			</view>

		</view>
		<view class="cart-list">
			<view class="list" v-for="(item, index) in markList" :key="index">
				<view class="check" @click="toggleCheck(index)">
					<text class="iconfont" :class="item.isChecked ? 'icon-checked' : 'icon-check'"></text>
				</view>
				<view class="goods">
					<view class="thumb">
						<image :src="item.logo_img" mode=""></image>
					</view>
					<view class="item">
						<view class="title">
							<view class="two-omit">{{ item.name }}</view>
						</view>
						<view class="title1">
							<view class="two-omit">{{ item.introduce }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>


		<view class="bottom">
			<view class="button" @click="next">
				下一步
			</view>
		</view>
	</view>
</template>

<script>
	
	import {
		getMarkListById
	} from '@/config/api.js';
	export default {
		data() {
			return {
				queryList:{
					navId: null,
					page: 1,
					name:'',
					limit: 20
				},
				markList: [],
				searchQuery: '', // 存储搜索内容
				location: '', // 存储位置信息
				pageTitle: '',
				goodsList: [{
						id: 1,
						name: 'BANDALY 2020夏季女装连衣裙韩版大码宽松显瘦套装裙子两件套 JX19301 上豆绿下米白 M ',
						price: '219.00',
						vip_price: '129.00',
						img: 'https://p3.ssl.qhimgs1.com/sdr/400__/t0485eb72d6fc28e0d9.jpg',
						attributes: ['金色', '大尺码'],
						is_goods: 0,
						isChecked: false,
					},
					{
						id: 1,
						name: '花花公子 卫衣男秋季圆领薄款休闲体恤男士时尚长袖T恤外套上衣男生情侣装套头衣服秋天男装 白色 XL',
						price: '139.00',
						vip_price: '99.00',
						attributes: ['银色', '中尺码'],
						img: 'https://p3.ssl.qhimgs1.com/sdr/400__/t0485eb72d6fc28e0d9.jpg',
						is_goods: 1,
						isChecked: false,
					},
					{
						id: 1,
						name: '戴尔(DELL)成就3681英特尔酷睿i5商用办公高性能台式机电脑整机(十代i5-10400 8G 1T 三年上门售后)21.5英寸',
						price: '3699.00',
						attributes: ['银色', '中尺码'],
						vip_price: '3600.00',
						img: 'https://p3.ssl.qhimgs1.com/sdr/400__/t0485eb72d6fc28e0d9.jpg',
						is_goods: 0,
						isChecked: false,
					},

				],
			};
		},
		// 在目标页面的 onLoad 方法中
		onLoad(options) {
			// 获取传递过来的标题
			const title = decodeURIComponent(options.title);

			// 可以将 title 设置为页面的标题或在页面中使用
			wx.setNavigationBarTitle({
				title: title
			});

			this.pageTitle = title
			this.queryList.navId = options.nav_id;
			this.markListById();
			console.log(options)
		},
		methods: {

			markListById(){
				getMarkListById(this.queryList).then(res => {
					res.data.forEach(el => {
						el['isChecked'] = false;
					});
					this.markList = res.data;
				})
			},
			// 获取用户定位
			getLocation() {
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						this.location = `${res.latitude}, ${res.longitude}`; // 存储经纬度
						uni.showToast({
							title: '定位成功',
							icon: 'success',
						});
						console.log('用户定位:', this.location);
					},
					fail: (err) => {
						uni.showToast({
							title: '获取定位失败',
							icon: 'none',
						});
						console.error(err);
					},
				});
			},
			// 执行搜索
			onSearch() {
				
				this.markListById();
				// if (this.searchQuery.trim()) {
				// 	uni.navigateTo({
				// 		url: `/pages/searchResults/searchResults?query=${encodeURIComponent(this.searchQuery)}`,
				// 	});
				// } else {
				// 	uni.showToast({
				// 		title: '请输入搜索内容',
				// 		icon: 'none',
				// 	});
				// }
			},
			//下一步
			toggleCheck(index) {
				this.markList.forEach(el => {
					el['isChecked'] = false;
				});
				this.markList[index]['isChecked'] = !this.markList[index]['isChecked'];
			},

			next() {
				const title = this.pageTitle;
				console.log('标题:', title);
				const data = this.markList.find(el=>el.isChecked);
				uni.navigateTo({
					url: `/moduleA/MerchantIn/360hang/360hang?title=${encodeURIComponent(title)}&nav_id=${this.queryList.navId}&store_id=${data.id}`
				})
			}
		},
	};
</script>



<style scoped lang="scss">
	.page {
		display: flex;
		flex-direction: column;
		// width: 94%;
		// margin: 100rpx 3%;
	}
		// 搜索框
		.article-search {
			position: fixed;
			left: 0;
			top: 0;
			z-index: 10;
			display: flex;
			align-items: center;
			width: 100%;
			height:100rpx;
			padding: 0 2%;
			background-color: #ffffff;
	
			.search {
				display: flex;
				align-items: center;
				padding: 0 0 0 3%;
				width: 96%;
				height: 60rpx;
				background-color: #f6f6f6;
				border-radius: 60rpx;
				.iconfont {
					font-size: 28rpx;
					color: #C0C0C0;
	
				}
	
				input {
					width: 90%;
					height: 100%;
					color: #212121;
					font-size: 24rpx;
					margin-left: 10rpx;
				}
	
				.search-button {
					height: 90%;
					width: 120rpx;
					font-size: 28rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background-color: $base;
					/* 按钮背景色 */
					color: #ffffff;
					/* 按钮文字颜色 */
					border: none;
					/* 去掉边框 */
					border-radius: 30rpx;
					/* 圆角 */
					cursor: pointer;
					/* 鼠标悬停时显示手型 */
				}
	
				.search-button:hover {
					background-color: #e68a00;
					/* 悬停效果 */
				}
			}
	
	}
	
		// 市场
		.cart-list{
		  width: 100%;
		  background-color: #FFFFFF;
		  padding: 20rpx 0;
		  margin-top: 100rpx;
		  /* #ifdef APP-PLUS */
		  margin-top: calc(100rpx + var(--status-bar-height));
		  /* #endif */
		  .list{
		    display: flex;
		    padding: 0 3%;
		    height: 240rpx;
		    margin-bottom: 20rpx;
		    .check{
		      display: flex;
		      align-items: center;
		      width: 10%;
		      height: 100%;
		      text{
		        font-size: 36rpx;
		        color: #333333;
		      }
		      .icon-checked{
		        color: $base;
		        // box-shadow: 0 0 10rpx $base;
		      }
		    }
		    .goods{
		      display: flex;
		      align-items: center;
		      width: 90%;
		      height: 100%;
		      background-color: #FFFFFF;
		      box-shadow: 0 0 20rpx #f6f6f6;
		      border-radius: 10rpx;
		      .thumb{
		        display: flex;
		        // align-items: center;
		        justify-content: center;
		        width: 30%;
		        height: 100%;
		        margin-top: 20rpx;
		        image{
		          width: 160rpx;
		          height: 160rpx;
		          border-radius: 10rpx;
		        }
		      }
		      .item{
		        padding: 10rpx 0;
		        width: 70%;
		        height: 100%;
		        .title{
		         
		          width: 100%;
		          font-size: 32rpx;
		          color: #212121;
		          font-weight: bold;
		          
		        }
				.title1{
				 
				  width: 100%;
				  
				    font-size: 26rpx;
				    color: #C0C0C0;
				  
				}
		      }
		    }
		  }
		}
		
	//下一步
		.bottom{
			position: fixed;
			bottom:0;
			width: 100%;
			height: 150rpx;
			background-color: #fff;
			.button{
				margin: 20rpx 30rpx;
				height: 100rpx;
				
				text-align: center;
				background-color: $base;
				line-height: 100rpx;
				border-radius: 50rpx;
				color: #fff;
				font-size: 32rpx;
			}
		}
		
		
	// @import 'boWuGuan.scss';
</style>